package com.smfx.yxt.view;

import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.smfx.yxt.common.Const;
import com.smfx.yxt.model.OrganizeDepart;
import com.smfx.yxt.model.TeacherInfo;
import com.smfx.yxt.wechat.utils.WechatGlobalMap;

public class TeacherInfoView extends TeacherInfo {

	private static final long serialVersionUID = 5209310646541550068L;
	
	private Integer clazz;
	
	public String getGradeText(){
		return TermView.getGradeName(super.getGrade(), super.getStudyType());
	}
	
	public String getSubjectText(){
		Integer subjectId = super.getSubjectId();
		if(subjectId != null) {
			Map<Integer, String> map = (Map<Integer, String>) WechatGlobalMap.get(Const.CACHE_SUBJECT).getValue();
			String subject = map.get(subjectId);
			if(StringUtils.isNotBlank(subject)) {
				return subject;
			}
		}
		return "无";
	}

	public Integer getClazz() {
		return clazz;
	}

	public void setClazz(Integer clazz) {
		this.clazz = clazz;
	}
	
	@SuppressWarnings("unchecked")
	public String getDepartText() {
		if(StringUtils.isNotBlank(super.getDepart())) {
			Map<String, OrganizeDepart> map = (Map<String, OrganizeDepart>) WechatGlobalMap.get(Const.CACHE_ORGANIZE_DEPART).getValue();
			String[] strings = super.getDepart().split(",");
			String value = "";
			for(int i = 0; i < strings.length; i++) {
				if(map.get(strings[i]) == null) {
					continue;
				}
				value += map.get(strings[i]).getDepart();
				if((i+1) != strings.length) value += ",";
			}
			return value;
		}
		return "";
	}
	
	@SuppressWarnings("unchecked")
	public String getPositionText() {
		if(StringUtils.isNotBlank(super.getPosition())) {
			Map<String, OrganizeDepart> map = (Map<String, OrganizeDepart>) WechatGlobalMap.get(Const.CACHE_ORGANIZE_DEPART).getValue();
			String[] strings = super.getPosition().split(",");
			String value = "";
			for(int i = 0; i < strings.length; i++) {
				if(map.get(strings[i]) == null) {
					continue;
				}
				value += map.get(strings[i]).getPosition();
				if((i+1) != strings.length) value += ",";
			}
			return value;
		}
		return "";
	}
	
}
